<?php  

require('init.php');
include('inc/top.php');

if ($user->data['user_id'] == ANONYMOUS) { echo '<div id="main_red"><p>You must be logged in to view this page.</p>'; } else {
if($userisadmin = false) { echo '<div id="main_red"><p>You must be verified with SourceBB to view this page.</p>'; } else {

$pagenum = $_GET['pagenum'];
if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 

$searchbox = sanitizeString($_POST['searchbox']);

if (isset($_POST['searchbox'])) {
$data_tmp = mysql_query("SELECT * FROM mysql_bans WHERE banned_by_id='$usersteamid' AND player_name LIKE '%{$searchbox}%'");
} else {
$data_tmp = mysql_query("SELECT * FROM mysql_bans WHERE banned_by_id='$usersteamid'")/*  or die(mysql_error()) */;
}

if ($data_tmp == NULL) { echo "<p>No Bans Found.</p>"; } else {

$rows = mysql_num_rows($data_tmp);
$pagenum = sanitizeString($pagenum); 
$page_rows = $maxresults; 
$last = ceil($rows/$page_rows); 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

if (isset($_POST['searchbox'])) {
$data_p = mysql_query("SELECT * FROM mysql_bans WHERE banned_by_id='$usersteamid' AND player_name LIKE '%{$searchbox}%' ORDER BY id DESC {$max}"); 
} else {
$data_p = mysql_query("SELECT * FROM mysql_bans WHERE banned_by_id='$usersteamid' ORDER BY id DESC $max"); 
}
}
?>

<div id="main_gray"><h1>My Bans</h1></div>

<table class="table" id="tableborder" cellpadding="5" cellspacing="0" align="center" width="400">
	<tr><th>
		<form method="post" name="searchform" action="mybans.php">
			<input name="searchbox" type="text" class="searchinput" />
			<input name="search" type="submit" value="Search" class="searchbutton" />
		</form>
	</th></tr></table>
<br />
<?php  

	if ($data_p == NULL) { echo "<div id='main_red'><p>No Bans Found.</p></div>"; } else {
	
?>
<div class="border2">
<table class="table" cellpadding="0" cellspacing="0" align="center" width="760">

<tr height="37" class="tr_th">
	<th>ID</th><th>Username</th><th>Ban Length</th><th>Reason</th><th>Admin</th><th>Banned on</th>
</tr>

<?php 
while($info = mysql_fetch_array( $data_p )) 
{ 


$banint = $info['ban_length'];
switch ($banint) {
case 0:
$bantime = "Permanent";
break;
case 1:
$bantime = "1 Minute";
break;
case ($banint < 60):
$bantime = "Less than 1 hour";
break;
case 60:
$bantime = "1 Hour";
break;
case (($banint > 60) && ($banint < 720)):
$bantime = "1-12 Hours";
break;
case 720:
$bantime = "12 Hours";
break;
case (($banint > 720) && ($banint < 1440)):
$bantime = "12-24 Hours";
break;
case 1440:
$bantime = "1 Day";
break;
case (($banint > 1440) && ($banint < 10080)):
$bantime = "1-7 Days";
break;
case 10080:
$bantime = "1 Week";
break;
case (($banint > 10080) && ($banint < 20160)):
$bantime = "1-2 Weeks";
break;
case 20160:
$bantime = "2 Weeks";
break;
case (($banint > 20160) && ($banint < 43200)):
$bantime = "2-4 Weeks";
break;
case 43200:
$bantime = "1 Month";
break;
case (($banint > 43200) && ($banint < 86400)):
$bantime = "1-2 Months";
break;
case 86400:
$bantime = "2 Months";
break;
case (($banint > 86400) && ($banint < 259200)):
$bantime = "2-6 Months";
break;
case 259200:
$bantime = "6 Months";
break;
case (($banint > 259200) && ($banint < 518400)):
$bantime = "6-12 Months";
break;
case 518400:
$bantime = "1 Year";
break;
case ($banint > 43200):
$bantime = "Over 1 Year";
break;
}


?>
		<tr onClick="parent.location='bandetails.php?banid=<?php  echo $info['id']; ?>'" onmouseover="cursor='pointer'" height="37" id="trhov">

			<td><?php  echo $info['id']; ?></td>
			<td><?php  echo $info['player_name']; ?></td>
			<td><?php  echo $bantime; ?></td>
			<td><?php  echo $info['ban_reason']; ?></td>
			<td><?php  echo $info['banned_by']; ?></td>
			<td><?php  echo date("M. j, Y g:i a", strtotime($info['timestamp'])); ?></td>
		</tr>

<?php 
}

?>
</table>
</div>

<?php 

echo "<p class='pages'>";
if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'><img src='images/icons/first.png' border='0'></a>";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'><img src='images/icons/back.png' border='0'></a>";
} 
echo " Page $pagenum of $last ";
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'><img src='images/icons/next.png' border='0'></a>";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'><img src='images/icons/last.png' border='0'></a>";
}
echo "</p>";
}
}
}
include('inc/bottom.php');
?>